import {defineStore} from "pinia";
import useUserStore from "@/pinia/stores/user";


const useCounterStore = defineStore("counterStore", {
    state() {
        return {
            counter: 1,

        }
    },
    actions: {
        // 基本使用
        add(state) {
            this.counter++
        },
        // 传递参数
        addArguments(value) {
            this.counter += value
        },
        // 执行异步操作
        asyncAdd(value) {
            return new Promise((resolve, reject) => {
                if (typeof value !== "number") {
                    reject(new Error("传入的参数只能是数字类型"))
                } else {
                    this.counter += value
                    resolve("执行成功")
                }
            })
        }
    },
    getters: {}
})
export default useCounterStore